import { Component, OnInit } from '@angular/core';
import { NavController, NavParams } from 'ionic-angular';
import { Park } from '../../providers/park-data/park';
import { User } from '../../providers/login-data/user';
import { Storage } from '@ionic/storage';
import { CommentInfo } from '../../providers/comment-data/comment';
import { CommentDataProvider } from '../../providers/comment-data/comment-data';



@Component({
  selector: 'page-park-comment',
  templateUrl: 'park-comment.html',
})

export class ParkCommentPage implements OnInit{
  park: Park;
  user: User;
  commentContent: string;

  constructor(public navCtrl: NavController, 
    public navParams: NavParams,
    public storage: Storage,
    public commentDataProvider: CommentDataProvider) {
  }
  ngOnInit(): void {
    this.park = this.navParams.get('park');
    
  }

  ionViewDidLoad() {
   this.storage.get('LOGIN_INFO').then(val=>{
      this.user = JSON.parse(val);
    });

    
  }
  

  postComment(){
    if(this.commentContent.length > 0){
      let _comment: CommentInfo = {
        content: this.commentContent,
        userId: this.user.objectId,
        parkId: this.park.objectId
      };
      this.commentDataProvider.addComment(_comment).toPromise().then(()=>{this.navCtrl.pop();});
    }
  }

}
